import requests
import xlwt
from io import BytesIO
from requests_toolbelt.multipart.encoder import MultipartEncoder
from lxml import etree
from collections import OrderedDict
from urllib3 import encode_multipart_formdata

from utils.tools import parse_number, get_file_content


# 导入excel，注意是xls格式的
def import_by_xls(book_details_json, session_id, discount):
    row_data_json = return_row_data(book_details_json, discount)
    if row_data_json['code'] != 200:
        return row_data_json
    row_data = row_data_json['data']
    print(row_data)
    # 创建一个Workbook对象
    wb = xlwt.Workbook()
    # 添加一个sheet
    ws = wb.add_sheet('Sheet1')
    # 写入标题行
    table_headers = [
        '系统内码', 'isbn', '书名', '定价', '出版年月',
        'CIP分类号', '作者', '供货折扣', '是否重点书', '每包扎数',
        '每扎册数', '编辑推荐', '作者简介', '内容摘要', '预计发货时间',
        '首印数', '广告语', '品牌（工作室）', '目录', '策划人',
        '读者对象', '建议采购数', '其他题名信息', '丛书题名', '分册号/名',
        '编著方式', '开本', '装帧', '页数', '主题词',
        '文献语种', '版次', '备注', '包销品种', '营销细类'
    ]
    # xls专用写法
    for col, header in enumerate(table_headers):
        ws.write(0, col, header)

    for col, value in enumerate(row_data):
        ws.write(1, col, value)

    # 将Excel文件保存到内存中
    excel_buffer = BytesIO()
    wb.save(excel_buffer)

    # 将工作簿保存到字节流中
    excel_buffer.seek(0)

    multipart_data = MultipartEncoder(
        fields={
            'file_path': ('111.xls', excel_buffer, 'application/vnd.ms-excel')
        },
        boundary='----WebKitFormBoundaryGwaQTIGlQsnTHrMd'
    )

    headers = {'Cookie': f'JSESSIONID={session_id}', 'Content-Type': multipart_data.content_type}
    response = requests.post('http://ghs.zxhsd.com/newBook/book_upload.jsp', headers=headers, data=multipart_data,
                             verify=False)
    excel_buffer.close()
    status_code = response.status_code
    response_text = response.text
    if status_code == 200 and '成功' in response_text:
        return {'code': 200, 'message': '导入成功', 'reason': response_text}
    else:
        return {'code': 0, 'message': '导入失败', 'reason': response_text}


def return_row_data(book_details_json, discount):
    row_data = [
        '', '', '', '', '',
        '', '', '', '', '',
        '', '', '', '', '',
        '', '', '', '', '',
        '', '', '', '', '',
        '', '', '', '', '',
        '', '', '', '', ''
    ]
    row_data[0] = book_details_json['serialNo']  # 系统内码
    row_data[1] = book_details_json['isbn'] or ''  # isbn
    row_data[2] = book_details_json['bookName'] or ''  # 书名
    row_data[3] = book_details_json['priceFixed'] or ''  # 定价
    row_data[4] = book_details_json['publishDate'] or ''  # 出版年月
    row_data[5] = book_details_json['bookInfoAppendObj']['classificationNumber'] or ''  # CIP分类号
    row_data[6] = book_details_json['authorName'] or ''  # 作者
    row_data[7] = discount  # 供货折扣
    row_data[8] = '否'  # 是否重点书
    row_data[9] = ''  # 每包扎数
    row_data[10] = ''  # 每扎册数
    row_data[11] = book_details_json['bookInfoAdditionObj']['editRecommend'] or ''  # 编辑推荐
    row_data[12] = book_details_json['bookInfoAdditionObj']['authorAbout'] or ''  # 作者简介
    row_data[13] = book_details_json['bookInfoAdditionObj']['briefIntroduction'] or ''  # 内容摘要
    row_data[14] = ''  # 预计发货时间
    row_data[15] = book_details_json['printNumber'] or ''  # 首印数
    row_data[16] = book_details_json['bookInfoAdditionObj']['advertisingSlogan'] or ''  # 广告语
    row_data[17] = ''  # 品牌（工作室）
    row_data[18] = book_details_json['bookInfoAdditionObj']['tableOfContents'] or ''  # 目录
    row_data[19] = ''  # 策划人
    row_data[20] = book_details_json['bookInfoAppendObj']['readerObject'] or ''  # 读者对象
    row_data[21] = ''  # 建议采购数
    row_data[22] = ''  # 其他题名信息
    row_data[23] = ''  # 丛书题名
    row_data[24] = ''  # 分册号/名
    row_data[25] = ''  # 编著方式
    row_data[26] = book_details_json['bookSize'] or ''  # 开本
    row_data[27] = book_details_json['binding'] or ''  # 装帧
    row_data[28] = parse_number(book_details_json['pagesNumber']) or ''  # 页数
    row_data[29] = book_details_json['wordsRecommend'] or ''  # 主题词 对应DCC的关键词推荐
    row_data[30] = ''  # 文献语种
    row_data[31] = book_details_json['versionNo'] or ''  # 版次  # 版次
    row_data[32] = ''  # 备注
    row_data[33] = ''  # 包销品种
    row_data[34] = ''  # 营销细类
    if not row_data[0]:
        return {'code': 0, 'message': '请传入系统内码！'}
    if not row_data[1]:
        return {'code': 0, 'message': '请传入isbn！'}
    if not row_data[2]:
        return {'code': 0, 'message': '请传入书名！'}
    if not row_data[3]:
        return {'code': 0, 'message': '请传入定价！'}
    if not row_data[4]:
        return {'code': 0, 'message': '请传入出版年月！'}
    if not row_data[5]:
        return {'code': 0, 'message': '请传入CIP分类号！'}
    if not row_data[6]:
        return {'code': 0, 'message': '请传入作者！'}
    if not row_data[7]:
        return {'code': 0, 'message': '请传入供货折扣！'}
    if not row_data[8]:
        return {'code': 0, 'message': '请传入是否重点书！'}
    return {'code': 200, 'data': row_data}


# 通过cip获取分类类型和分类code
def get_kind_by_cip(cip, session_id):
    cookies = {
        'JSESSIONID': session_id,
    }
    data = {
        'cip': cip,
    }
    response = requests.post('http://ghs.zxhsd.com/newBook/ajaxCip.jsp', cookies=cookies, data=data, verify=False)
    response_list = response.text.split("\r\n")
    if response_list[1] == 'true':
        return {'code': 200, 'data': {
            'kind_id': response_list[2],
            'kind_name': response_list[3],
        }}
    else:
        return {'code': 0, 'data': {}, 'message': '没有找到相关数据'}


def return_zz_code(data):
    if data is None or data == '':
        return '0'
    else:
        obj = {
            '活页': '5',
            '平装': '1',
            '精装': '3',
            '线装': '4',
            '其他': '0',
        }
        return obj.get(data, '0')


# 直接发布包括传图片
def publishProductSingle_all(book_details_json, session_id, discount, self_id):
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
        'Cache-Control': 'no-cache',
        'Content-Type': 'multipart/form-data;boundary=----WebKitFormBoundaryKPjN0GYtWEjAni5F',
        'Cookie': 'JSESSIONID=' + session_id,
        'Origin': 'http://ghs.zxhsd.com',
        'Pragma': 'no-cache',
        'Proxy-Connection': 'keep-alive',
        'Referer': 'http://ghs.zxhsd.com/newBook/book_edit.jsp?act=new',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
    }
    banquan_dcc_url_content = ''
    liti_dcc_url_content = ''
    transparent_dcc_url_content = ''
    # 版权页
    book_info_file_obj_list = book_details_json['bookInfoFileObjList']
    banquan_dcc_url = next((item for item in book_info_file_obj_list if item["fileType"] == "4"), None)
    if banquan_dcc_url:
        res = get_file_content(banquan_dcc_url['webUrl'])
        if res:
            banquan_dcc_url_content = res['content']
    # 立体封
    liti_dcc_url = next((item for item in book_info_file_obj_list if item["fileType"] == "1"), None)
    if liti_dcc_url:
        res = get_file_content(liti_dcc_url['webUrl'])
        if res:
            liti_dcc_url_content = res['content']
    # 透明图
    transparent_dcc_url = next((item for item in book_info_file_obj_list if item["fileType"] == "9"), None)
    if transparent_dcc_url:
        res = get_file_content(transparent_dcc_url['webUrl'])
        if res:
            transparent_dcc_url_content = res['content']
    cip_data = get_kind_by_cip(book_details_json.get('bookInfoAppendObj', {}).get('classificationNumber', ''),
                               session_id)
    params = OrderedDict([("act", (None, 'new', 'multipart/form-data')),  # 动作：新增
                          ("xs_id", (None, '', 'multipart/form-data')),  # 系统商品id 新增则为空
                          ('sfqr', (None, '', 'multipart/form-data')),  # 是否确认 新增默认空
                          ('captchaWord', (None, 'rdh5', 'multipart/form-data')),  # 不知道是什么
                          ('sfzds', (None, '0', 'multipart/form-data')),  # 是否重点书 0:否 1:是  -- 必填
                          ('sm', (None, (book_details_json.get('bookName') or '').encode('gb2312', errors='ignore'),
                                  'multipart/form-data')),  # 书名  -- 必填
                          ('isbn', (None, book_details_json.get('isbn') or '', 'multipart/form-data')),  # ISBN -- 必填
                          ('qrczisbn', (None, '0', 'multipart/form-data')),  # 和ISBN一起的hidden，新增好像都是0
                          ('dj', (None, book_details_json.get('priceFixed') or '', 'multipart/form-data')),  # 定价 -- 必填
                          ('ghsnm', (None, self_id, 'multipart/form-data')),  # 商品内码(自编码) -- 必填
                          ('cbrq', (None, book_details_json.get('publishDate') or '', 'multipart/form-data')),
                          # 出版年月 -- 必填
                          ('zyz', (None, (book_details_json.get('authorName') or '').encode('gb2312', errors='ignore'),
                                   'multipart/form-data')),
                          # 作者 -- 必填
                          ('ghzk', (None, discount, 'multipart/form-data')),  # 供货折扣(数字) -- 必填
                          ('cipfl', (
                          None, book_details_json.get('bookInfoAppendObj', {}).get('classificationNumber') or '',
                          'multipart/form-data')),  # CIP分类 -- 必填
                          ('yxfl', (None, cip_data.get('data', {}).get('kind_id') or '', 'multipart/form-data')),
                          # 分类ID
                          ('flName', (None, (cip_data.get('data', {}).get('kind_name') or '').encode('gb2312', errors='ignore'), 'multipart/form-data')),
                          # 分类名称
                          ('cwdl', (None, '', 'multipart/form-data')),
                          # 财务大类 。。。好像填了cip之后就不需要选财务大类了，直接填空字符串就行，页面上也不会有财务大类这个选择框了
                          ('fmtplx', (None, '0', 'multipart/form-data')),  # 立体封面图 上传文件类型 0 附件 1 网址
                          ('fmtpfile', ('lt.jpg', liti_dcc_url_content, 'application/octet-stream')),
                          # 立体封面图  立体封面图（格式JPEG、小于1M)： 二进制流文件
                          ('fdtplx', (None, '0', 'multipart/form-data')),  # 封底图 上传文件类型 0 附件 1 网址
                          ('fdtpfile', ('', '', 'application/octet-stream')),  # 封底图（条码区平面图、格式JPEG、小于1M)： 二进制流文件
                          ('bcylx', (None, '0', 'multipart/form-data')),  # 版权页 上传文件类型 0 附件 1 网址
                          ('bcyfile', ('lt.jpg', banquan_dcc_url_content, 'application/octet-stream')),
                          # 版权页（格式JPEG、小于1M)： 二进制流文件
                          ('hblx', (None, '0', 'multipart/form-data')),  # 海报 上传文件类型 0 附件 1 网址
                          ('hbfile', ('', '', 'application/octet-stream')),  # 海报（小于5M）： 二进制流文件
                          ('jctplx', (None, '0', 'multipart/form-data')),  # 精编插图 上传文件类型 0 附件 1 网址
                          ('jctpfile', ('', '', 'application/octet-stream')),  # 精编插图（小于5M）: 二进制流文件
                          ('tmsctlx', (None, '0', 'multipart/form-data')),  # 透明素材图 上传文件类型 0 附件 1 网址
                          ('tmsctfile', ('tm.png', transparent_dcc_url_content, 'application/octet-stream')),
                          # 透明素材图（立体封面，PNG格式，尺寸在800*800px以上，小于5M）: 二进制流文件
                          ('bjtj', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('editorRecommend') or '').encode('gb2312', errors='ignore'),
                                    'multipart/form-data')),  # 编辑推荐
                          ('zzjj', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('authorAbout') or '').encode('gb2312', errors='ignore'),
                                    'multipart/form-data')),  # 作者简介
                          ('nrjj', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('briefIntroduction') or '').encode('gb2312', errors='ignore'),
                                    'multipart/form-data')),  # 内容提要（必填） -- 好像只是写的是必填
                          ('yjfhsj', (None, '', 'multipart/form-data')),  # 预计发货时间（必填）（必填） -- 好像只是写的是必填
                          ('sys', (None, (book_details_json.get('printNumber') or '').encode('gb2312', errors='ignore'), 'multipart/form-data')),
                          # 首印数（必填） -- 好像只是写的是必填
                          ('ggy', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('advertisingSlogan') or '').encode('gb2312', errors='ignore'),
                                   'multipart/form-data')),  # 广告语
                          ('pp', (None, '', 'multipart/form-data')),  # 品牌（工作室）
                          ('ml', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('tableOfContents') or '').encode('gb2312', errors='ignore'),
                                  'multipart/form-data')),  # 目录
                          ('dzdx', (None, (book_details_json.get('readerObject') or '').encode('gb2312', errors='ignore'), 'multipart/form-data')),  # 读者对象
                          ('chr', (None, '', 'multipart/form-data')),  # 策划人
                          ('jyds', (None, '', 'multipart/form-data')),  # 建议采购数
                          ('jcy', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('onlineReading') or '').encode('gb2312', errors='ignore'),
                                   'multipart/form-data')),  # 精彩试读
                          ('sp', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('mediaReview') or '').encode('gb2312', errors='ignore'),
                                  'multipart/form-data')),  # 媒体评论
                          ('xy', (None, (book_details_json.get('bookInfoAdditionObj', {}).get('preface') or '').encode('gb2312', errors='ignore'),
                                  'multipart/form-data')),  # 前言
                          ('hj', (None, '', 'multipart/form-data')),  # 后记
                          ('qttmxx', (None, '', 'multipart/form-data')),  # 其他题名信息
                          ('cstm', (None, (book_details_json.get('bookInfoAppendObj', {}).get('seriesTitleName') or '').encode('gb2312', errors='ignore'),
                                    'multipart/form-data')),  # 丛书题名
                          ('fch', (None, '', 'multipart/form-data')),  # 分册号/名
                          ('bzfs', (None, '', 'multipart/form-data')),  # 编著方式
                          ('kbm', (None, (book_details_json.get('bookSize') or '').encode('gb2312', errors='ignore'), 'multipart/form-data')),  # 开本
                          ('zz', (None, return_zz_code(book_details_json.get('binding')), 'multipart/form-data')),  # 装帧
                          ('ysstr', (None,  book_details_json.get('pagesNumber') or '', 'multipart/form-data')),  # 页数
                          ('wxyz', (None, book_details_json.get('textLanguage') or '', 'multipart/form-data')),  # 文献语种
                          ('bcstr', (None, book_details_json.get('versionNo') or '', 'multipart/form-data')),  # 版次
                          ('ztc', (None, '', 'multipart/form-data')),  # 主题词
                          ('bxpz', (None, '0', 'multipart/form-data')),  # 包销品种 默认 0 否0  是1
                          ('ghsbz', (None, '', 'multipart/form-data')),  # 备注
                          ('tm', (None, book_details_json.get('isbn') or '', 'multipart/form-data')),  # 条码
                          ('yz', (None, book_details_json.get('printPage') or '', 'multipart/form-data')),  # 印张
                          ('ysny', (None, '', 'multipart/form-data')),  # 印刷年月
                          ('yc', (None, parse_number(book_details_json['printNo'] or ''), 'multipart/form-data')),  # 印次(数字)
                          ('zs', (None, parse_number(book_details_json.get('fontNumber') or ''), 'multipart/form-data')),  # 字数(数字)
                          ('yc', (None, '', 'multipart/form-data')),  # 发行范围
                          ('fxfw', (None, '', 'multipart/form-data')),  # 重量(数字)
                          ('mbzs', (None, '', 'multipart/form-data')),  # 每包扎数
                          ('mzcs', (None, '', 'multipart/form-data')),  # 每扎册数
                          ])
    m = encode_multipart_formdata(params, boundary='----WebKitFormBoundaryKPjN0GYtWEjAni5F')
    response = requests.post('http://ghs.zxhsd.com/newBook/book_save.jsp', headers=headers, data=m[0])
    # response.text 包含 插入新书成功
    if "插入新书成功" in response.text:
        return {'code': 200, 'message': '插入新书成功', 'reason': response.text}
    else:
        return {'code': 0, 'message': '插入新书失败', 'reason': response.text}


# 获取当前货品goodsId
def get_current_goods_id(session_id, isbn, price):
    cookies = {
        'JSESSIONID': session_id,
    }
    isbn = isbn.strip()
    price = float(price)
    data = {
        'act': 'search',
        'orderDrop': 'isbn',
        's_isbn': isbn,
        's_sm': '',
        's_ghsnm': '',
        's_sfqr': '0',
        'curpage': [
            '1',
            '1',
        ],
        'currpg': '1',
    }
    response = requests.post('http://ghs.zxhsd.com/newBook/book_list.jsp', cookies=cookies, data=data, verify=False)
    et = etree.HTML(response.text)
    trs = et.xpath('.//tr')
    c_id = ''
    newTrs = []
    for tr in trs:
        print(''.join(tr.itertext()))
        trInnerText = ''.join(tr.itertext())
        if isbn in trInnerText:
            newTrs.append(tr)
    if len(newTrs) == 0:
        return {'code': 0, 'data': {}, 'message': '没有找到相关数据'}
    for tr in newTrs:
        a = tr.xpath('.//td')
        isbn = a[1].xpath('.//text()')[0].strip()
        column_price = float(a[5].xpath('.//text()')[0].replace('￥', ''))
        if isbn == isbn and price == column_price:
            c_id = a[0].xpath('.//input')[0].get('value')
            break
    return {'code': 200, 'data': {
        'c_id': c_id
    }, 'message': '获取成功'}
# def import_by_single_base(book_details_json, session_id, discount):
#     params = OrderedDict([
#         ("act", (None, 'new', 'multipart/form-data')),  # 动作：新增
#         ("xs_id", (None, '', 'multipart/form-data')),  # 系统商品id 新增则为空
#         ('sfqr', (None, '', 'multipart/form-data')),
#         ('captchaWord', (None, 'rdh5', 'multipart/form-data')),
#         ('sfzds', (None, '0', 'multipart/form-data')),  # 是否重点书 0:否 1:是  -- 必填
#         ('sm', (None, (book_details_json['bookName'] or '').encode('gb2312', errors='ignore'), 'multipart/form-data')),
#         # 书名  -- 必填
#         ('isbn', (None, book_details_json['isbn'], 'multipart/form-data')),  # ISBN -- 必填
#         ('qrczisbn', (None, '0', 'multipart/form-data')),  # 和ISBN一起的hidden，新增好像都是0
#         ('dj', (None, '18.80', 'multipart/form-data')),  # 定价 -- 必填
#         ('ghsnm', (None, 'yems-7295', 'multipart/form-data')),  # 商品内码(自编码) -- 必填
#         ('cbrq', (None, '2024-04', 'multipart/form-data')),  # 出版年月 -- 必填
#         ('zyz', (None, ('范丽').encode('gb2312', errors='ignore'), 'multipart/form-data')),  # 作者 -- 必填
#         ('ghzk', (None, '52', 'multipart/form-data')),  # 供货折扣(数字) -- 必填
#     ])
#
#     return {
#         'book_details_json': book_details_json,
#         'session_id': session_id,
#         'discount': discount
#     }


# 通过cip获取分类类型和分类code
# def get_kind_by_cip(cip, session_id):
#     cookies = {
#         'JSESSIONID': session_id,
#     }
#     data = {
#         'cip': cip,
#     }
#     response = requests.post('http://ghs.zxhsd.com/newBook/ajaxCip.jsp', cookies=cookies, data=data, verify=False)
#     response_list = response.text.split("\r\n")
#     if response_list[1] == 'true':
#         return {'code': 200, 'data': {
#             'kind_id': response_list[2],
#             'kind_name': response_list[3],
#         }}
#     else:
#         return {'code': 0, 'data': {}, 'message': '没有找到相关数据'}


# 基础上架代码防丢失
# coding: utf-8
# from collections import OrderedDict
# import requests
# from urllib3 import encode_multipart_formdata
#
# headers = {
#     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
#     'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
#     'Cache-Control': 'no-cache',
#     'Content-Type': 'multipart/form-data;boundary=----WebKitFormBoundaryKPjN0GYtWEjAni5F',
#     'Cookie': 'JSESSIONID=556E01208C0E1BEA68BB2F5E9240CC8A',
#     'Origin': 'http://ghs.zxhsd.com',
#     'Pragma': 'no-cache',
#     'Proxy-Connection': 'keep-alive',
#     'Referer': 'http://ghs.zxhsd.com/newBook/book_edit.jsp?act=new',
#     'Upgrade-Insecure-Requests': '1',
#     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
# }
#
# params = OrderedDict([("act", (None, 'new', 'multipart/form-data')),  # 动作：新增
#                       ("xs_id", (None, '', 'multipart/form-data')),  # 系统商品id 新增则为空
#                       ('sfqr', (None, '', 'multipart/form-data')),
#                       ('captchaWord', (None, 'rdh5', 'multipart/form-data')),
#                       ('sfzds', (None, '0', 'multipart/form-data')),  # 是否重点书 0:否 1:是  -- 必填
#                       ('sm', (None, ('幼儿创意美术画册1').encode('gb2312', errors='ignore'), 'multipart/form-data')),  # 书名  -- 必填
#                       ('isbn', (None, '9787573147295', 'multipart/form-data')),  # ISBN -- 必填
#                       ('qrczisbn', (None, '0', 'multipart/form-data')),  # 和ISBN一起的hidden，新增好像都是0
#                       ('dj', (None, '18.80', 'multipart/form-data')),  # 定价 -- 必填
#                       ('ghsnm', (None, 'yems-7295', 'multipart/form-data')),  # 商品内码(自编码) -- 必填
#                       ('cbrq', (None, '2024-04', 'multipart/form-data')),  # 出版年月 -- 必填
#                       ('zyz', (None, ('范丽').encode('gb2312', errors='ignore'), 'multipart/form-data')),  # 作者 -- 必填
#                       ('ghzk', (None, '52', 'multipart/form-data')),  # 供货折扣(数字) -- 必填
#                       ('cipfl', (None, 'G613.6', 'multipart/form-data')),  # CIP分类 -- 必填
#                       ('yxfl', (None, 'EAAB0', 'multipart/form-data')),
#                       ('flName', (None, '', 'multipart/form-data')),
#                       ('cwdl', (None, '', 'multipart/form-data')),
#                       ('fmtplx', (None, '0', 'multipart/form-data')),
#                       ('fmtpfile', ('', '', 'application/octet-stream')),
#                       ('fdtplx', (None, '0', 'multipart/form-data')),
#                       ('fdtpfile', ('', '', 'application/octet-stream')),
#                       ('bcylx', (None, '0', 'multipart/form-data')),
#                       ('bcyfile', ('', '', 'application/octet-stream')),
#                       ('hblx', (None, '0', 'multipart/form-data')),
#                       ('hbfile', ('', '', 'application/octet-stream')),
#                       ('jctplx', (None, '0', 'multipart/form-data')),
#                       ('jctpfile', ('', '', 'application/octet-stream')),
#                       ('tmsctlx', (None, '0', 'multipart/form-data')),
#                       ('tmsctfile', ('', '', 'application/octet-stream')),
#                       ('bjtj', (None, '', 'multipart/form-data')),
#                       ('zzjj', (None, '', 'multipart/form-data')),
#                       ('nrjj', (None, '', 'multipart/form-data')),
#                       ('yjfhsj', (None, '', 'multipart/form-data')),
#                       ('sys', (None, '', 'multipart/form-data')),
#                       ('ggy', (None, '', 'multipart/form-data')),
#                       ('pp', (None, '', 'multipart/form-data')),
#                       ('ml', (None, '', 'multipart/form-data')),
#                       ('dzdx', (None, '', 'multipart/form-data')),
#                       ('chr', (None, '', 'multipart/form-data')),
#                       ('jyds', (None, '', 'multipart/form-data')),
#                       ('jcy', (None, '', 'multipart/form-data')),
#                       ('sp', (None, '', 'multipart/form-data')),
#                       ('xy', (None, '', 'multipart/form-data')),
#                       ('hj', (None, '', 'multipart/form-data')),
#                       ('qttmxx', (None, '', 'multipart/form-data')),
#                       ('cstm', (None, '', 'multipart/form-data')),
#                       ('fch', (None, '', 'multipart/form-data')),
#                       ('bzfs', (None, '', 'multipart/form-data')),
#                       ('kbm', (None, '', 'multipart/form-data')),
#                       ('zz', (None, '', 'multipart/form-data')),
#                       ('ysstr', (None, '', 'multipart/form-data')),
#                       ('wxyz', (None, '', 'multipart/form-data')),
#                       ('bcstr', (None, '', 'multipart/form-data')),
#                       ('ztc', (None, '', 'multipart/form-data')),
#                       ('bxpz', (None, '0', 'multipart/form-data')),
#                       ('ghsbz', (None, '', 'multipart/form-data')),
#                       ('tm', (None, '', 'multipart/form-data')),
#                       ('yz', (None, '', 'multipart/form-data')),
#                       ('ysny', (None, '', 'multipart/form-data')),
#                       ('yc', (None, '', 'multipart/form-data')),
#                       ('zs', (None, '', 'multipart/form-data')),
#                       ('yc', (None, '', 'multipart/form-data')),
#                       ('fxfw', (None, '', 'multipart/form-data')),
#                       ('mbzs', (None, '', 'multipart/form-data')),
#                       ('mzcs', (None, '', 'multipart/form-data')),
#                       ])
# m = encode_multipart_formdata(params, boundary='----WebKitFormBoundaryKPjN0GYtWEjAni5F')
#
# print(m[0])
# response = requests.post('http://ghs.zxhsd.com/newBook/book_save.jsp', headers=headers, data=m[0])
# print(response.request.body)
# print(response.text)
